package com.yangguang.huahui.mvp.model;

import com.yangguang.huahui.api.PurchaseApi;
import com.yangguang.huahui.api.SupplyApi;
import com.yangguang.huahui.entity.BuyEditInfo;
import com.yangguang.huahui.entity.ClientNeeds;
import com.yangguang.huahui.entity.HttpResult;
import com.yangguang.huahui.entity.PublishList;
import com.yangguang.huahui.net.NetManager;
import com.yangguang.huahui.utils.SignUtil;

import java.util.HashMap;
import java.util.Map;

import rx.Observable;

/**
 * Created by Administrator on 2017/3/6.
 */

public class PurchaseModel {
    /**
     * 客户需求
     * @param page
     * @return
     */
    public Observable<ClientNeeds> client_needs_list(int page){
        PurchaseApi purchaseApi = NetManager.getInstance().create(PurchaseApi.class);
        return purchaseApi.client_needs_list(page);
    }

    /**
     * 发布采购
     * @param uid
     * @param goods_type
     * @param variety
     * @param goods_title
     * @param high_price
     * @param low_price
     * @param demand
     * @param source_id
     * @param receipt_address
     * @return
     */
    public Observable<HttpResult> publish(String uid, String goods_type, String variety, String goods_title, String high_price,
                                          String low_price, String demand, String source_id, String receipt_address, String deadline,
                                          String contacts, String phone, String remark){
        PurchaseApi purchaseApi = NetManager.getInstance().create(PurchaseApi.class);
        return purchaseApi.publish(uid, goods_type, variety, goods_title, high_price, low_price, demand, source_id, receipt_address,
                deadline, contacts, phone, remark);
    }

    public Observable<PublishList> getPublish(String uid){
        PurchaseApi purchaseApi = NetManager.getInstance().create(PurchaseApi.class);
        return purchaseApi.getPublish(uid);
    }

    public Observable<PublishList> delete(String id){
        PurchaseApi purchaseApi = NetManager.getInstance().create(PurchaseApi.class);
        return purchaseApi.delete(id);
    }

    public Observable<PublishList> refresh(String id, String uid){
        PurchaseApi purchaseApi = NetManager.getInstance().create(PurchaseApi.class);
        return purchaseApi.refresh(id, uid);
    }

    public Observable<BuyEditInfo> getInfo(String id){
        PurchaseApi purchaseApi = NetManager.getInstance().create(PurchaseApi.class);
        return purchaseApi.getInfo(id);
    }

    public Observable<HttpResult> edit(String id, String paramKey, String paramValue){
        PurchaseApi purchaseApi = NetManager.getInstance().create(PurchaseApi.class);
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put(paramKey, paramValue);
        return purchaseApi.edit(map, SignUtil.getSign(map));
    }
}
